package org.example.service.simple;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Tang
 * @classname SimpleRevicer
 * @description [  ]
 * @date 2023/4/10 21:26
 */
@Component
public class SimpleRevicer {

    @RabbitListener(queues = {"ex.tang.test01"})
    public void test01Handler(String msg, @Headers Map<String, Object> headers, Channel channel) {
        System.out.println("收到的消息---》" + msg);
        try {
            Long deliveryTag  = (Long)headers.get(AmqpHeaders.DELIVERY_TAG);
            System.out.println("deliveryTag：" + deliveryTag);
            channel.basicAck(deliveryTag,false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
